<?php
/////////////////////////////////////////////////////////////////////////////
// 
//
// workflow_system
//
// workflow_copyright
// 
/////////////////////////////////////////////////////////////////////////////

/**
 * FILE_NAME : productmessage.class.php   FILE_PATH : \\classes\application\productmessage.class.php
 * ....商品留言类
 *
 * @copyright workflow_system 
 * @author workflow Develop Team 
 * @package 
 * @subpackage 
 * @version Fri Oct 12 16:47:27 CST 2007
 */

class ProductMessageClass extends FrameWork {
	/**
	 * 商品留言
	 *
	 * @param var[] $input_param
	 * @return boolen
	 */
	function addMessage($input_param){
		$valueArray = array();
		$valueArray['member_name'] = $input_param['MemberName'];
		$valueArray['message_content'] = $input_param['txtMessage'];
		$valueArray['product_id'] = $input_param['hideproductID'];
		$valueArray['product_code'] = $input_param['pid'];
		$valueArray['member_id'] = $input_param['hidememberID'];
		$valueArray['message_time'] = time();
		if ($input_param['anonymous'] == '1'){
			$valueArray['anonymous'] = $input_param['anonymous'];
		}
		$insert_rs = $GLOBALS['db']->InsertRow($valueArray, 'product_message', 'message_id');
		return $insert_rs;
	}

	/**
	 * 店主回复商品留言
	 *
	 * @param var[] $input_param
	 * @return boolen
	 */
	function reMessage($input_param){
		$valueArray = array();
		$valueArray['message_recontent'] = $input_param['txtReMessage'];
		$valueArray['re_time'] = time();
		$update_rs = $GLOBALS['db']->UpdateRow($input_param["hideMessageID"],$valueArray, 'product_message', 'message_id');
		return $update_rs;
	}

	/**
	 * 删除商品留言
	 *
	 * @param var[] $input_id
	 * @param int $member_id
	 * @return boolen
	 */
	function deleteOperateMessage($input_id,$member_id){
		if (is_array($input_id)){
			foreach ($input_id as $value){
				if (intval($value) > 0){
					$this->_deleteMessage($value,$member_id);
				}
			}
		}else{
			if (intval($input_id) > 0){
				$this->_deleteMessage($input_id,$member_id);
			}
		}
		return true;
	}

	/**
	 * 删除某个商铺某个留言
	 *
	 * @param int $input_id 留言ID
	 * @param int $member_id 卖家ID
	 * @return boolen
	 */
	function _deleteMessage($input_id,$member_id){
		if (intval($input_id) > 0){
			$GLOBALS['db']->DeleOneRow('','product_message','',"where message_id = " . intval($input_id) . " and member_id='" . $member_id . "'");
		}
		return true;
	}
	
	/**
	 * 通过id 删除留言
	 * @author workflow Develop Team     
	 * @param  
	 * @return bool
	 */
	function delMessage($msg_id){
		if (intval($msg_id) > 0){
			$result = $GLOBALS['db']->DeleOneRow($msg_id,'product_message','message_id');
			return $result;
		}else {
			return false;
		}
	}
	
	/**
	 * 查看某商品的留言
	 *
	 * @param int $shop_id
	 */
	function getMessage(&$obj_page,$product_id,$isre=false){
		if ($isre == true){
			$substr = "and message_recontent<>''";
		}
		$message_array = $GLOBALS['db']->GetList("and product_id='" . $product_id . "' " . $substr . " order by message_time desc",$obj_page,"product_message");
		return $message_array;
	}

	/**
	 * 查看某卖家/买家留言
	 *
	 * @param obj $obj_page
	 * @param int $member_id
	 * @param boolen $isre
	 * @param string $genre
	 * @return var[]
	 */
	function getProductMessage(&$obj_page,$member_id="",$isre=false,$genre="sale",$condition=''){
		if ($isre == true){
			$substr = "and product_message.message_recontent<>''";
		}
		if ($genre == "sale"){
			$substr .= " and product_message.member_id='" . $member_id . "'";
		}else if ($genre == "buy"){
			$substr .= " and product_message.member_name='" . $member_id . "'";
		}
		//检索条件
		if ($condition['p_name'] != ''){
			$substr .= " and product.p_name like '%" . $condition['p_name'] . "%'";
		}
		if ($condition['member_name'] != ''){
			$substr .= " and product_message.member_name = '" . $condition['member_name'] . "'";
		}
		if ($condition['seller'] != ''){
			$substr .= " and member.login_name = '" . $condition['seller'] . "'";
		}
		
		$message_array = $GLOBALS['db']->GetJoinList($obj_page,array('product_message','product','member'),"inner join",array("product_message.product_id=product.p_id",'product_message.member_id=member.member_id'),array('*','p_name','login_name'),$substr,array(" message_time desc"));
		return $message_array;
	}

	/**
	 * 得到某条留言
	 *
	 * @param int $message_id  留言ID
	 * @param int $member_id   卖家ID
	 * @return var[]
	 */
	function getOneMessage($message_id,$member_id){
		if (intval($member_id) > 0){
			$message_array = $GLOBALS['db']->GetJoinList($obj_page,array('product_message','product','member'),"left join",array("product_message.product_id=product.p_id",'product_message.member_id=member.member_id'),array("message_id,member_name,message_content,message_recontent,product_id,product_code,message_time,re_time,anonymous","*",'login_name'),"where product_message.member_id='" . $member_id . "' and product_message.message_id='" . $message_id . "'",0,array(" message_time desc"));
			return $message_array;
		}else {
			return false;
		}
	}

	/**
	 * 留言是否存在
	 *
	 * @param var[] $arr 键messageid留言ID，productid产品ID，memberid所属卖家ID
	 * @return boolen
	 */
	function isExistMessage($arr){
		$message_array = $GLOBALS['db']->GetList(" and message_id='" . $arr['messageid'] . "' and product_id='" . $arr['productid'] . "' and member_id='" . $arr['memberid'] . "'",$page,'product_message','message_id');
		if (count($message_array) > 0){
			return true;
		}else{
			return false;
		}
	}
	
	/**
	 * 删除店主回复商品留言
	 *
	 * @param var[] $input_param
	 * @return boolen
	 */
	function reclearMessage($input_param){
		$valueArray = array();
		$valueArray['message_recontent'] = "";
		$valueArray['re_time'] = "";
		$update_rs = $GLOBALS['db']->UpdateRow($input_param["messageid"],$valueArray, 'product_message', 'message_id');
		return $update_rs;
	}
	
	/**
	 * 更新留言信息
	 * @author workflow Develop Team     
	 * @param  $param 更新参数
	 * @return bool
	 */
	function updateMessage($param){
		if (intval($param['message_id']) > 0){
			$valueArray = array();
			foreach ($param as $k => $v){
				$valueArray[$k] = $v;
			}
			$result = $GLOBALS['db']->UpdateRow(intval($valueArray['message_id']),$valueArray, 'product_message', 'message_id');
			unset($value_array,$valueArray);
			return $result;
		}else {
			return false;
		}
	}
	
}
?>